package com.springbootblog.controller.fontend.thread;

import javax.swing.plaf.nimbus.State;

public class TestState implements Runnable
{
    @Override
    public void run()
    {
        for (int i = 0; i < 5; i++)
        {
            try {
                Thread.sleep(50);
            } catch (
                    InterruptedException e) {
                throw new RuntimeException(e);
            }
            // 线程输出
            System.out.println("for is running ! ");
        }
    }

    public static void main(String[] args) throws InterruptedException
    {
        TestState testState = new TestState();
        Thread thread = new Thread(testState);
        // 获取线程状态
        Thread.State state = thread.getState();
        // new
        System.out.println("26:"+state);

        // 开启线程
        thread.start();
        // 30:RUNNABLE
        state = thread.getState();
        System.out.println("30:"+state);

        // 线程未停止
        while(state != Thread.State.TERMINATED)
        {
            Thread.sleep(100);
            // 线程未结束:TIMED_WAITING
            // 线程以结束:TERMINATED
            state = thread.getState();
            System.out.println("36:"+state);
        }
    }
}
